﻿@model IList<UserMessageEntity>
<div class="layui-card">
	<div class="layui-form layui-card-header layuiadmin-card-header-auto" style="padding-top:0px;padding-bottom:0px;">
		<div class="layui-form-item">
			<div class="layui-inline" style="margin-right: 0;">
				<label class="layui-form-label" style="padding:0px;padding-right: 5px;width:100px;">
					<select id="dropSearchName" name="dropSearchName">
						<option value="Title">标题</option>
						<option value="[Content]">内容</option>
						<option value="Incept">收件人</option>
						<option value="Sender">发件人</option>
					</select>
				</label>
				<div class="layui-input-inline" style="margin: 0px;">
					<input type="text" class="layui-input" id="txtSearchKeyword" name="txtSearchKeyword" placeholder="请输入搜索关键字" autocomplete="off" onkeypress="javascript:return DefaultButton(event, 'btnSearch')">
				</div>
			</div>
			<div class="layui-inline">
				<button id="btnSearch" type="button" class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="btnSearch">
					<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
				</button>
			</div>
		</div>
	</div>

	<div class="layui-card-body">
		<div class="layui-tab layui-tab-brief" lay-filter="tabList">
			<ul class="layui-tab-title">
				<li lay-id="-1" class="layui-this">全部</li>
				<li lay-id="0">未读消息</li>
				<li lay-id="1">已读消息</li>
			</ul>
			<div class="layui-tab-content">
				<table id="tblList" lay-filter="tblList"></table>
			</div>
		</div>
		<input type="hidden" id="hidTab" value="-1" />
		<script type="text/html" id="toolbarHead">
			<div class="layui-form-item" style="margin: auto;">
				<div class="layui-inline">
					<div class="layui-input-inline layui-input-company"><strong>删除</strong></div>
					<span class="select-box inline">
						<select id="dropBatchDelType" class="select" onchange="SelectDelType()" lay-ignore>
							<option value="0">发件人</option>
							<option value="1" selected="selected">指定日期范围内</option>
						</select>
					</span>
					<span class="select-box inline">
						<input type="text" class="layui-input" id="txtSender" placeholder="多个发件人用“,”分隔" style="display:none; height:30px;" />
						<select id="dropDelDate" class="select" lay-ignore>
							<option value="1">一天前</option>
							<option value="3">三天前</option>
							<option value="7" selected="selected">一星期前</option>
							<option value="30">一个月前</option>
							<option value="60">两个月前</option>
							<option value="180">半年前</option>
							<option value="0">所有</option>
						</select>
					</span>
					<div class="layui-input-inline layui-input-company" style="float:none;">
						<strong>的站内信</strong>
						<button class="layui-btn layuiadmin-btn-list" onclick="DelMessageBatch()">执行选定的操作</button>
					</div>
				</div>
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="btnDeleteMulti">批量删除</button>
					<button class="layui-btn layuiadmin-btn-list" onclick="layer_show('发送站内信','/Admin/Plus/MessageSend')">发送站内信</button>
				</div>
			</div>
		</script>
		<script type="text/html" id="statusText">
			{{#  if(d.IsDelInbox == 2){ }}
			<button class="layui-btn layui-btn-primary layui-btn-xs">已清</button>
			{{#  } else if(d.IsDelInbox == 1){ }}
			<button class="layui-btn layui-btn-primary layui-btn-xs">已删</button>
			{{#  } else if(d.IsRead == 1){ }}
			<button class="layui-btn layui-btn-primary layui-btn-xs">已读</button>
			{{#  } else{ }}
			<button class="layui-btn layui-btn-primary layui-btn-xs layui-bg-red">未读</button>
			{{#  } }}
		</script>
		<script type="text/html" id="statusText1">
			{{#  if(d.IsDelSendbox == 2){ }}
			<button class="layui-btn layui-btn-primary layui-btn-xs">已清</button>
			{{#  } else if(d.IsDelSendbox == 1){ }}
			<button class="layui-btn layui-btn-primary layui-btn-xs">已删</button>
			{{#  } else if(d.IsSend == 1){ }}
			<button class="layui-btn layui-btn-primary layui-btn-xs">已发</button>
			{{#  } else{ }}
			<button class="layui-btn layui-btn-primary layui-btn-xs layui-bg-red">未发</button>
			{{#  } }}
		</script>
		<script type="text/html" id="tblBarCol">
			<a class="layui-btn layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-search"></i>查看</a>
		</script>
	</div>
</div>
@Html.AntiForgeryToken()
@section scripts {
	<script type="text/javascript">
		layui.use(['form', 'table', 'element'], function () {
			var table = layui.table;
			var form = layui.form;
			var element = layui.element;

			//获取hash来切换选项卡，假设当前地址的hash为lay-id对应的值
			var layid = location.hash.replace(/^#tabList=/, '');
			if (layid != null && layid != "") {
				element.tabChange('tabList', layid);
				$("#hidTab").val(layid);
			}
			//监听Tab切换，以改变地址hash值
			element.on('tab(tabList)', function () {
				location.href = location.pathname + "#tabList=" + this.getAttribute('lay-id');
				window.location.reload();
			});

			//加载表格
			table.render({
				elem: '#tblList'
				, url: '/Admin/Plus/GetMessageList'
				, toolbar: '#toolbarHead'
				, where: GetSearchParam()
				, request: {
					pageName: 'PageNum' //页码的参数名称，默认：page
					, limitName: 'PageSize' //每页数据量的参数名，默认：limit
				}
				, cols: [[
					{ type: "checkbox", width: 30, fixed: "left", align: 'center' },
					{ field: 'Title', minWidth: 200, title: '标题', align: 'left' },
					{ field: 'Incept', width: 100, title: '收件人', align: 'center', templet: '<div><a class="layui-btn layui-btn-xs" href="javascript:;" onclick="layer_showFull(\'查看会员\',\'/Admin/User/UserShow?UserName={{d.Incept}}\')">{{d.Incept}}</a></div>' },
					{ field: 'IsDelInbox', width: 100, title: '收件人状态', align: 'center', templet: '#statusText' },
					{ field: 'Sender', width: 100, title: '发件人', align: 'center', templet: '<div><a class="layui-btn layui-btn-xs" href="javascript:;" onclick="layer_showFull(\'查看会员\',\'/Admin/User/UserShow?UserName={{d.Sender}}\')">{{d.Sender}}</a></div>' },
					{ field: 'IsDelSendbox', width: 100, title: '发件人状态', align: 'center', templet: '#statusText1' },
					{ field: 'SendTime', width: 180, title: '发送日期', align: 'center', templet: function (d) { return (d.SendTime == null ? "" : (formatDateTime(d.SendTime) == "9999-12-31 23:59:59") ? "" : formatDateTime(d.SendTime)); } },
					{ field: 'MessageID', title: '操作', width: 100, fixed: "right", align: "center", templet: '#tblBarCol' }
				]]
				, parseData: function (res) { //res 即为原始返回的数据
					return {
						"code": 0, //解析接口状态
						"msg": "", //解析提示文本
						"count": res.RecordTotal, //解析数据长度
						"data": res.RowList //解析数据列表
					};
				}
				, limits: [10, 15, 20, 25, 50, 100]
				, limit: 10
				, page: true
			});
			//监听表格操作列
			table.on('tool(tblList)', function (obj) {
				if (obj.event === 'view') {
					layer_show('查看站内信', '/Admin/Plus/ViewMessage?id=' + obj.data.MessageID);
					return false;
				}
			});
			//监听搜索操作
			form.on('submit(btnSearch)', function (data) {
				reloadTable();
				return false;
			});
			//监听批量删除
			form.on('submit(btnDeleteMulti)', function (data) {
				var checkStatus = table.checkStatus('tblList');
				var data = checkStatus.data;
				var ids = "";
				for (j = 0, len = data.length; j < len; j++) {
					if (j < len - 1) {
						ids += data[j].MessageID + ',';
					} else {
						ids += data[j].MessageID;
					}
				}
				DeleteMulti(ids, '/Admin/Plus/DelMessageMulti');
				return false;
			});

			//表格重载
			function reloadTable(tableID = 'tblList') {
				table.reload(tableID, {
					page: {
						curr: 1
					}
					, where: GetSearchParam()
				}, 'data');
			};
			function GetSearchParam() {
				var SearchName = $("#dropSearchName").val();
				var SearchKeyword = $("#txtSearchKeyword").val();
				var TabStatus = $("#hidTab").val();
				var objParam = { "SearchName": SearchName, "SearchKeyword": SearchKeyword, "TabStatus": TabStatus };
				return objParam;
			};
			SelectDelType();
		});
		function DelMessageBatch() {
			//询问框
			layer.confirm("您确认删除选定的记录吗？", {
				btn: ["确定", "取消"]
			}, function () {
				var DelType = $("#dropBatchDelType").val();
				var DelValue = "";
				if (DelType == "0") {
					DelValue = $("#txtSender").val();
				}
				else {
					DelValue = $("#dropDelDate").val();
				}
				if (DelValue.length <= 0) {
					layer.alert('请指定要删除的发件人或日期');
					return;
				}
				var url = "/Admin/Plus/DelMessageBatch";
				var sendData = { "DelType": DelType, "DelValue": DelValue };
				$.ajax({
					type: "Post",
					url: url,
					data: sendData,
					headers: {
						"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
					},
					error: function (data, status, e) {
						layer.alert('操作失败!');
					},
					success: function (data) {
						if (data.Result == "ok") {
							layer.alert('操作成功!');
							setTimeout('window.location.reload()', 1000);
						}
						else {
							layer.alert(data.Result);
						}
					}
				});
			});
		}
		function SelectDelType() {
			var DelType = $("#dropBatchDelType").val();
			if (DelType == "1") {
				$("#txtSender").hide();
				$("#dropDelDate").show();
			}
			else {
				$("#txtSender").show();
				$("#dropDelDate").hide();
			}
		}
	</script>
}